using UnityEngine;
using System.Collections;

/// \class  gkAbyssalGiantSubmarinePickUpAnimationController
/// \brief  Launch the pickUp animation when picking up a boost
[AddComponentMenu("GK/AbyssalGiant/Submarine/gkAbyssalGiantSubmarinePickUpAnimationController")]
public class gkAbyssalGiantSubmarinePickUpAnimationController : MonoBehaviour 
{
	/// The pickup animation state
	private AnimationState m_rPickUpAnimationState;
	
	/// \brief  Called just after the game begin to play
	void Start()
	{
		// Grab the pick up animation state
		m_rPickUpAnimationState = animation["Submarine_PickUp"];
			
		// Place the invincibilty phase on the effects animation layer
		m_rPickUpAnimationState.layer = 1;
		
	}
	
	/// \brief  Called when the component is enabled
	void OnEnable() 
	{
		// Listen the pickUp event
		GetComponent<gkEventComponent>().AddEventHandler(gkAbyssalGiantPickUpEvent.PickUp, HandlePickUpEvent);
	}
	
	/// \brief  Called when the component is disabled
	void OnDisable() 
	{	
		// Remove the pickUp event
		GetComponent<gkEventComponent>().RemoveEventHandler(gkAbyssalGiantPickUpEvent.PickUp, HandlePickUpEvent);
	}
	
	/// Handle the pickUp event
	void HandlePickUpEvent(Object a_rEvent)
	{
		animation.Blend(m_rPickUpAnimationState.name, 1.0f, 0.0f);
		m_rPickUpAnimationState.time = 0;
	}
}
